local ads__dichou = fk.CreateSkill({
  name = "ads__dichou",
})


Fk:loadTranslationTable{
  ["ads__dichou"] = "地臭",
  [":ads__dichou"] = "一名其他角色造成伤害时，你可以令该角色弃置一张黑桃牌，将伤害转移给一名角色，然后你摸X张牌（X为该角色当前的体力值）。",
  ["#ads__dichou-choose"] = "地臭：令伤害来源弃置一张黑桃牌，将伤害转移给一名角色，然后你摸X张牌（X为伤害来源当前体力值）",
  ["$ads__dichou2"] = "接着哦~",
  ["$ads__dichou1"] = "替我挡着~",
}

ads__dichou:addEffect(fk.DetermineDamageCaused, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target ~= player and data.from and data.from ~= player and player:hasSkill(ads__dichou.name) and data.skillName ~= ads__dichou.name
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local damage_source = data.from
    if not damage_source then
      return false
    end
    local has_spade_card = false
    local handcards = damage_source:getCardIds(Player.Hand)
    for _, card_id in ipairs(handcards) do
      local card = Fk:getCardById(card_id)
      if card.suit == Card.Spade then
        has_spade_card = true
        break
      end
    end
    if not has_spade_card then
      return false
    end
    local tos = room:askToChoosePlayers(player, {
      skill_name = ads__dichou.name,
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player, false),
      prompt = "#ads__dichou-choose",
      cancelable = true,
    })
    if #tos == 0 then
      return false
    end
    local cards = room:askToChooseCards(damage_source, {
      target = damage_source,
      min = 1,
      max = 1,
      flag = "hand",
      pattern = ".|spade|.|hand",
      skill_name = ads__dichou.name,
      prompt = "请弃置一张黑桃牌",
    })
    
    if #cards == 0 then
      return false
    end
    
    event:setCostData(self, {tos = tos, cards = cards, damage_source = damage_source})
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cost_data = event:getCostData(self)
    local damage_source = cost_data.damage_source
    local to = cost_data.tos[1]
    local cards = cost_data.cards
    
    if cards and #cards > 0 then
      room:throwCard(cards, ads__dichou.name, damage_source, damage_source)
    end
    
    local n = data.damage
    data:preventDamage()
    
    if not to.dead then
      room:damage{
        from = data.from,
        to = to,
        damage = n,
        damageType = data.damageType,
        skillName = data.skillName,
        chain = data.chain,
        card = data.card,
      }
    end
    
    if not player.dead then
      player:drawCards(damage_source.hp, ads__dichou.name)
    end
  end,
})


ads__dichou:addAI({
  think_skill_invoke = Util.TrueFunc,
})


return ads__dichou
